var SearchForm = function () {
  var template = /* html */ `
    <div class="search-form">
      <sys-common-search request-url="materialSelectFilter/getMaterialSelectData" :request-data="{type:22}" :search="search"
        :search-field="searchField" label-width="100px" input-width="180px" :dropdown-props="searchDropdownProps"
        v-loading.fullscreen.lock="loading">
        <template slot="append">
          <el-form-item label="预计收款日期">
            <el-date-picker v-model="search.startDate" class="form-input" value-format="timestamp" :editable="false"
              :picker-options="startDateOption" style="width:229px;"></el-date-picker>
            -
            <el-date-picker v-model="search.endDate" class="form-input" value-format="timestamp" :editable="false" :picker-options="endDateOption"
              style="width:229px;"></el-date-picker>
          </el-form-item>
          <el-form-item label="是否结算">
            <el-select clearable v-model="search.isBalance" class="form-input" style="width:180px;">
              <el-option v-for="balance in balanceList" :key="'balance_'+balance.value" :value="balance.value" :label="balance.label">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="制单人" v-if="!search.fixedCreateUser">
            <el-select clearable v-model="search.createUser" class="form-input" style="width:180px;">
              <el-option v-for="user in userList" :key="'user_'+user.userId" :value="user.userId" :label="user.userName"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="单价">
            <el-input-number is-decimal-zero v-model="search.startPrice" placeholder="单价最小值" :controls="false" :min="0" :max="search.endPrice"
              :precision="2" style="width:110px"></el-input-number>
            <span>-</span>
            <el-input-number is-decimal-zero v-model="search.endPrice" placeholder="单价最大值" :controls="false" :precision="2"
              :min="search.startPrice?search.startPrice:0" style="width:110px"></el-input-number>
          </el-form-item>
        </template>
      </sys-common-search>
    </div>
  `;

  return {
    mixins: [datePickerOptionsMixin('startDate', 'endDate')],

    props: {
      search: {
        type: Object,
        required: true
      },
      dropdownOption: {
        type: Object,
        default: function () {
          return {};
        }
      }
    },

    data: function () {
      return {
        searchField: ['orderId', 'companyOrderId', 'customerNo', 'factoryNo', 'materialName', 'model', 'color', 'providerName', 'materialDept'],
        searchDropdownProps: {
          providerName: "客户"
        },
        balanceList: i18n.getDropDown('financeMgr.balance', ['0', '1']),
        userList: []
      };
    },

    created: function () {
      var self = this;
      this.loading = true;
      this.setUserList().then(function () {
        self.loading = false;
      }).catch(function () {
        self.loading = false;
      });
    },

    methods: {
      setUserList: function () {
        var dropdownOption = this.dropdownOption;
        var userList = dropdownOption.userList;
        if (userList !== undefined) {
          this.userList = userList;
          return Promise.resolve(userList);
        }

        var self = this;
        return ajaxRequest('warehouseInSumMoney/getWarehouseUserList').then(function (userList) {
          dropdownOption.userList = userList;
          self.userList = userList;
          return userList;
        });
      }
    },

    components: {
      SysCommonSearch: SysCommonSearch
    },

    template: template
  };
}();
